<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>02_Lodash-手写简版</title>
</head>
<body>

  <script>
    ;(function(g) {
      function Lodash() {

      }

      // 添加类方法
      Lodash.VERSION = '1.0.0'
      Lodash.isArray = function(value) {
        return Object.prototype.toString.call(value) === '[object Array]'
      }

      // 添加实例方法
      Lodash.prototype.forEach = function(array, iteratee) {
        for (let i = 0; i < array.length; i++) {
          iteratee(array[i], i, array)
        }
      }

      // 添加静态方法
      Lodash.forEach = function(array, iteratee) {
        for (let i = 0; i < array.length; i++) {
          iteratee(array[i], i, array)
        }
      }

      Lodash.debounce = function() {}
      Lodash.throttle = function() {}
      Lodash.random = function() {}
      Lodash.endsWith = function() {}
      Lodash.clone = function() {}
      Lodash.cloneDeep = function() {}
      Lodash.merge = function() {}

      g._ = Lodash

    })(window)
  </script>

  <script>

    // 使用
    console.log(_.VERSION)
    console.log(_.isArray([1, 2, 3]))
    _.forEach([1, 2, 3], function(item, index, array) {
      console.log(item, index, array)
    })
    _.forEach([1, 2, 3], function(item, index, array) {
      console.log(item, index, array)
    })

  </script>
  
</body>
</html>